const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8000 });
// 存储连接的客户端
const clients = new Set();
wss.on('connection', (ws) => {
    // 添加新连接的客户端
    clients.add(ws);
    ws.on('message', (message) => {
        // 接收到客户端的消息
        // 将消息发送给其他客户端
        clients.forEach((client) => {
            if (client !== ws && client.readyState === WebSocket.OPEN) {
                client.send(message);
            }
        });
    });
    ws.on('close', () => {
        // 移除断开连接的客户端
        clients.delete(ws);
    });
});